/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.PhimPoJo;
import java.sql.ResultSet;

/**
 *
 * @author tran quoc thinh
 */
public class PhimDAO {
    public static ResultSet DSPhim()
    {
        try
        {
        ResultSet rs;
        MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
        dahp.Open();
        String sql = "select * from phim where tinhtrang = 1";
        rs = dahp.excecuteQuery(sql);
        //dahp.Close();
        return rs;
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());            
        }
        return null;
    }
    public static int ThemPhim(PhimPoJo p)
    {
        MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
        helper.Open();
        String sql=String.format("INSERT INTO phim (MaPhim,TenPhim,GioiThieu,TinhTrang)"
                + "VALUES('%s','%s','%s',%d)",p.getMaPhim(),p.getTenPhim(),p.getGioiThieu(),p.getTinhtrang());
        int n=helper.excecuteUpdate(sql);
        helper.Close();
        return n;
    }
     public static int SuaPhim(PhimPoJo p)
    {
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("UPDATE phim SET TenPhim='%s',GioiThieu='%s',TinhTrang='%d' WHERE MaPhim='%s'",p.getTenPhim(),p.getGioiThieu(),p.getTinhtrang(),p.getMaPhim());
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
      public static int XoaPhim(String maPhim){
        
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("DELETE FROM Phim WHERE MaPhim='%s'",maPhim );
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
}
